package cn.pet.service.manage.auth.util;

import cn.pet.service.manage.auth.entity.UserPermission;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtil {

    /**
     * 获取用户信息
     * @return
     */
    public static UserPermission getUserPermission(){
        try {
           return (UserPermission) getAuthentication().getPrincipal();
        }catch (Exception e){
            throw new RuntimeException("获取用户信息错误");
        }
    }

    /**
     * 获取Authentication
     */
    public static Authentication getAuthentication()
    {
        return SecurityContextHolder.getContext().getAuthentication();
    }



}
